package com.atguigu.phoenix.thick;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class PhoenixThickClientDemo {
    public static void main(String[] args) {
        testSelect();
    }

    public static void testSelect(){
        try {
            Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
            String url = "jdbc:phoenix:hadoop102,hadoop103,hadoop104:2181" ;
            Properties properties = new Properties();
            properties.put("phoenix.schema.isNamespaceMappingEnabled" , "true");
            Connection connection = DriverManager.getConnection(url , properties );
            String sql = "select id ,name ,addr from test1 where id = ? " ;
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1 , "1001");
            ResultSet resultSet = preparedStatement.executeQuery();
            if(resultSet.next()){
                String line = resultSet.getString("id") + " : " +
                        resultSet.getString("name") + " : " +
                        resultSet.getString("addr");
                System.out.println(line);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            //关闭资源
        }
    }
}
